package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AuthRoleModel;
import com.snake.springboot.authority.api.service.AuthRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类 {@code AuthRoleController}  <br> .
 * <p>权限管理-角色
 * 创建时间：2024/5/30 17:19
 *
 * @author Yzhui
 * @see
 */

@Api(tags = "权限管理-角色")
@RestController
@RequestMapping("/auth/role")
public class AuthRoleController {

    private AuthRoleService authRoleService;

    @Autowired
    public AuthRoleController(AuthRoleService authRoleService) {
        this.authRoleService = authRoleService;
    }

    @ApiOperation("添加角色")
    @PostMapping("/add")
    public ResponseResult<AuthRoleModel> addAuthRole(
            @ApiParam(name = "权限角色入参", value = "传入json格式", required = true)
            @RequestBody AuthRoleModel model) throws Exception {
        AuthRoleModel result = authRoleService.addRole(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @ApiOperation("修改角色")
    @PostMapping("/modify")
    public ResponseResult<AuthRoleModel> modifyAuthRole(
            @ApiParam(name = "权限角色入参", value = "传入json格式", required = true)
            @RequestBody AuthRoleModel model) throws Exception {
        authRoleService.modifyRole(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("删除角色")
    @GetMapping("/remove/{roleid}")
    public ResponseResult<AuthRoleModel> removeAuthRole(
            @ApiParam(name = "权限角色ID", value = "传入json格式", required = true)
            @PathVariable("roleid") String roleId) {
        authRoleService.removeRole(roleId);
        return ResponseResultFactory.ucc("删除成功！");
    }

    @ApiOperation("查询角色列表")
    @PostMapping("/list")
    public ResponseResult<List<AuthRoleModel>> queryAuthRolelist(
            @ApiParam(name = "权限角色ID", value = "传入json格式", required = true)
            @RequestBody AuthRoleModel params) throws Exception {
        List<AuthRoleModel> result = authRoleService.queryRoleList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }

}
